package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

public class StudentDao {
    private static Student[] arr = new Student[5];

    public boolean addStudent(Student stu) {
        int a = -1;
        for (int i = 0; i < arr.length; i++) {
            Student student = arr[i];
            if (student == null) {
                a = i;
                break;
            }
        }
        if (a == -1) {
            return false;
        } else {
            arr[a] = stu;
            return true;
        }
    }

    public static Student[] findAllStudent() {
        return arr;
    }

    public void byetid(String id) {
        int a = cxid(id);
        arr[a] = null;

    }

    public int cxid(String id) {
        int a = -1;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != null && arr[i].getId().equals(id)) {
                a = i;
                break;
            }
        }
        return a;
    }

    public void xgid(Student stu, String id) {
        int a = cxid(id);
        arr[a] = stu;
    }
}

